package com.dmagic.cms.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dmagic.cms.common.dao.CommonDao;
import com.dmagic.cms.common.exception.ServiceException;
import com.dmagic.cms.common.exception.ValidateException;
import com.dmagic.cms.common.query.PageUtil;
import com.dmagic.cms.common.service.CommonService;
import com.dmagic.cms.common.util.StringUtil;
import com.dmagic.cms.dao.InquireInfoDao;
import com.dmagic.cms.entity.InquireInfo;
import com.dmagic.cms.service.InquireInfoService;

@Service
@Transactional(readOnly = true, rollbackFor = ValidateException.class)
public class InquireInfoServiceImpl extends CommonService<InquireInfo> implements InquireInfoService {
	@Autowired
	private InquireInfoDao inquireInfoDao;

	@Override
	protected CommonDao<InquireInfo, Serializable> getCommonDao() {
		return (CommonDao) inquireInfoDao;
	}

	@Override
	@Transactional(readOnly = false)
	public void saveInquireInfo(InquireInfo[] inquireInfo) throws ValidateException {
		for (InquireInfo i : inquireInfo) {
			if (StringUtil.isBlank(i.getConsultant())) {
				continue;
			}
			saveEntity(i);
		}
	}

	@Override
	public void search(PageUtil<Map> pageUtil) throws ServiceException {
		try {
			inquireInfoDao.search(pageUtil);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}

	@Override
	public InquireInfo getInquireInfo(Long inquireInfoId) throws ServiceException {
		return getEntityById(inquireInfoId);
	}

	@Override
	@Transactional(readOnly = false)
	public void deleteInquireInfo(List<Long> inquireInfoIds) throws ServiceException {
		for (Long inquireInfoId : inquireInfoIds) {
			deleteEntityById(inquireInfoId);
		}
	}

	@Override
	@Transactional(readOnly = false)
	public void deleteInquireInfo(Long inquireInfoId) throws ServiceException {
		deleteEntityById(inquireInfoId);
	}
}
